package heliotrope.res.manager
{
	import heliotrope.config.ConfigPool;
	import heliotrope.global.GlobalVar;
	import heliotrope.net.loader.CommonLoader;
	import heliotrope.net.loader.ILoadTarget;
	import heliotrope.net.loader.IStateTarget;
	import heliotrope.net.loader.ITargetHost;
	import heliotrope.game.system.LoadSystem;
	import heliotrope.net.loader.LoadType;
	import heliotrope.res.BitmapdataDistributor;
	import heliotrope.res.GraphicResource;
	import heliotrope.res.ResourceMission;
	import heliotrope.res.TileResource;

	public class GraphicLoadManager
	{
		private static var __instance:GraphicLoadManager;
		
		private var _loadSys:LoadSystem;
		private var _configPool:ConfigPool;
		
		public function GraphicLoadManager(pvt:PrivateClass)
		{
			_loadSys = LoadSystem.getInstance();
			_configPool = ConfigPool.getInstance();
		}
		
		public function loadTile(id_:uint, x_:uint, y_:uint, host_:ITargetHost, target_:IStateTarget):void
		{
			var mission:ResourceMission = new ResourceMission(
				_configPool.source+"/Graphics/TileSets/"+id_+"/Tiles/"+"x"+x_+"y"+y_+"z0.jpg",
				target_, LoadType.PIC, host_)
			_loadSys.queueLoader.addMission(mission);
		}
		
		public function loadThumb(id_:uint, host_:ITargetHost, target_:IStateTarget):void
		{
			var mission:ResourceMission = new ResourceMission(
				_configPool.source+"/Graphics/TileSets/"+id_+"/thumbMap.jpg",
				target_, LoadType.PIC, host_)
			_loadSys.queueLoader.addMission(mission);
		}
		
		public function loadGraphic(index_:String, name_:String, host_:ITargetHost, target_:IStateTarget):void
		{
			var mission:ResourceMission = new ResourceMission(
				_configPool.source+"/Graphics/"+index_+"/"+name_,
				target_, LoadType.PIC, host_)
			_loadSys.queueLoader.addMission(mission);
		}
		
		public static function init():void
		{
			if(GraphicLoadManager.__instance)
			{
				throw new Error("You can't init the GraphicLoadManager twice!")
			}
			GraphicLoadManager.__instance = new GraphicLoadManager(new PrivateClass);
		}
		
		public static function getInstance():GraphicLoadManager
		{
			if(!GraphicLoadManager.__instance)
			{
				throw new Error("You should init the GraphicLoadManager at first!")
			}
			return GraphicLoadManager.__instance;
		}
		
	}
}

class PrivateClass
{
	public function PrivateClass()
	{
	}
}